package com.freak.neteasecloudmusic.modules.find.recommend.songlist;

import com.freak.httphelper.ApiCallback;
import com.freak.httphelper.HttpMethods;
import com.freak.httphelper.RxPresenter;
import com.freak.httphelper.SubscriberCallBack;
import com.freak.neteasecloudmusic.app.api.ApiService;
import com.freak.neteasecloudmusic.commom.constants.Constants;
import com.freak.neteasecloudmusic.modules.find.recommend.entity.SongListCategoryEntity;
import com.freak.neteasecloudmusic.net.log.LogUtil;
import com.freak.neteasecloudmusic.utils.ToastUtil;

import javax.inject.Inject;

import io.reactivex.Observable;

/**
 * @author Administrator
 */
public class SongListPresenter extends RxPresenter<SongListContract.View> implements SongListContract.Presenter {
    ApiService mApiService = HttpMethods.getInstance().create(ApiService.class);

    public SongListPresenter() {
    }

    @Inject
    public SongListPresenter(SongListContract.View view) {
        mView = view;
    }


    /**
     * 获取歌曲分类
     */
    @Override
    public void loadSongListCategory() {
        Observable<SongListCategoryEntity> observable = mApiService.loadSongListCategory();
        addSubscription(observable, new SubscriberCallBack<>(new ApiCallback<SongListCategoryEntity>() {
            @Override
            public void onSuccess(SongListCategoryEntity model) {
                if (model.getCode() == Constants.SUCCESS_CODE) {
                    mView.loadSongListCategorySuccess(model);
                } else {
                    ToastUtil.shortShow(model.getMsg() + "");
                }
            }

            @Override
            public void onFailure(String msg) {
                LogUtil.e(msg);
            }
        }));
    }


}
